package com.yoomiito.app.utils.wx;

import android.app.Activity;
import android.graphics.Bitmap;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ShareUtils {

    public static void shareWX(Activity activity, List<String> picUrls, String content) {
        List<Bitmap> bitmaps = new ArrayList<>();
        if (picUrls == null || picUrls.size() == 0) {
//            WXShareMultiImageHelper.shareToSession(this,bitmaps , dataBean.getContent());
            UMengShareUtils.shareWXText(activity, content);
        } else {
            Observable.fromIterable(picUrls)
                    .subscribeOn(Schedulers.io())
                    .map(url -> Glide.with(activity).asBitmap().load(url).submit().get())
                    .map(bitmap -> {
                        bitmaps.add(bitmap);
                        return bitmaps;
                    })
                    .filter(bitmaps1 -> bitmaps1.size() == picUrls.size() ? true : false)
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .subscribe(bitmaps1 -> WXShareMultiImageHelper.shareToSession(activity, bitmaps, content));
        }

    }
}
